<!--
 * @Autor: lh
 * @Date: 2023-08-21 09:50:00
 * @LastEditors: lh
 * @LastEditTime: 2023-10-20 10:02:25
 * @Description: 
-->
<script lang="ts" setup>
import { type ListItem } from "./data"
import { formatDateTime } from "@/utils/index"
import { useRouter } from "vue-router"

const useRouterHook = useRouter()

interface Props {
  list: ListItem[]
}

const props = defineProps<Props>()

const showDetails = (it: any) => {
  // localStorage.setItem("tableDataRule", JSON.stringify(it.tableDataRule))
  // localStorage.setItem("rowTable", JSON.stringify(row))
  // localStorage.setItem("rowTableName", '待办任务')
  useRouterHook.push({
    path: it.path
  })
}
</script>

<template>
  <el-empty v-if="props.list.length === 0" />
  <el-card v-else v-for="(item, index) in props.list" :key="index" shadow="never" class="card-container">
    <template #header>
      <div class="card-header" @click="showDetails(item)">
        <div>
          <span>
            <span class="card-title">{{ item.sourceModule }}</span>
            <el-tag v-if="item.extra" :type="item.status" effect="plain" size="small">{{ item.extra }}</el-tag>
          </span>
          <div class="card-time">{{ formatDateTime(item.createTime) }}</div>
        </div>
        <div v-if="item.avatar" class="card-avatar">
          <img :src="item.avatar" width="34" />
        </div>
      </div>
    </template>
    <div class="card-body" @click="showDetails(item)">
      {{ item.title }}
    </div>
  </el-card>
</template>

<style lang="scss" scoped>
.card-container {
  margin-bottom: 10px;
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .card-title {
      font-weight: bold;
      margin-right: 10px;
    }
    .card-time {
      font-size: 12px;
      color: grey;
    }
    .card-avatar {
      display: flex;
      align-items: center;
    }
  }
  .card-body {
    font-size: 12px;
  }
}
</style>
